/**
 * 
 */
package com.mzba.place.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.mzba.place.R;
import com.mzba.place.entity.CommentsEntity;
import com.mzba.place.entity.ReportUserEntity;
import com.mzba.place.utils.ImageLoader;
import com.mzba.place.utils.StringUtil;

/**
 * 列表适配器
 * 
 * @author iris
 * 
 */
public class ReportDetailAdapter extends BaseAdapter {

	public List<CommentsEntity> commentsList;
	private LayoutInflater layoutInflater;
	ImageLoader mImageLoader;

	public ReportDetailAdapter(Context context, List<CommentsEntity> commentsList,ImageLoader mImageLoader) {
		this.commentsList = commentsList;
		this.mImageLoader = mImageLoader;
		layoutInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return commentsList == null ? 0 : commentsList.size();
	}

	@Override
	public Object getItem(int arg0) {
		return commentsList == null ? null : commentsList.get(arg0);
	}

	@Override
	public long getItemId(int position) {
		return commentsList.get(position).getId();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;

		if (convertView == null) {
			convertView = layoutInflater.inflate(
					R.layout.activity_report_detail_item, null);
			holder = new ViewHolder();
			holder.tv_user_name = (TextView) convertView.findViewById(R.id.tv_user_name);
			holder.tv_report_comment = (TextView) convertView.findViewById(R.id.tv_comment);
			holder.iv_user_icon = (ImageView) convertView.findViewById(R.id.iv_user_icon);
			convertView.setTag(holder);

		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		CommentsEntity commentsEntity = commentsList.get(position);
		ReportUserEntity reportUserEntity = commentsEntity.getUser();
		if (!StringUtil.isBlank(commentsEntity.getContent()) ) {
			holder.tv_report_comment.setText(commentsEntity.getContent() + "");
		}
		holder.tv_user_name.setText(reportUserEntity.getScreen_name());
		if (StringUtil.isBlank(reportUserEntity.getProfile_image_url())) {
			holder.iv_user_icon.setVisibility(View.GONE);
		}else {
			holder.iv_user_icon.setVisibility(View.VISIBLE);
			mImageLoader.addTask(reportUserEntity.getProfile_image_url(),holder.iv_user_icon);
		}
		return convertView;
	}

	static class ViewHolder {

		ImageView iv_user_icon;
		TextView tv_user_name;
	
		TextView tv_report_comment;
	}

	/**
	 * @return the commentsList
	 */
	public List<CommentsEntity> getCommentsList() {
		return commentsList;
	}

	/**
	 * @param commentsList the commentsList to set
	 */
	public void setCommentsList(List<CommentsEntity> commentsList) {
		this.commentsList = commentsList;
	}

	

	
	
	
}
